package cn.kgc.service;

import cn.kgc.entity.Users;
import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

/**
 * @author YC
 */
@LocalTCC
public interface UserTccService {

    /**
     * try操作-注册用户
     *
     * @param actionContext 上下文
     * @param phoneNum      手机号
     * @return true/false
     */
    @TwoPhaseBusinessAction(
            //try操作的名称,全局唯一
            name = "tryRegisterUser",
            //commit方法
            commitMethod = "commitRegisterUser",
            //rollback方法
            rollbackMethod = "cancelRegisterUser"
    )
    Users tryRegisterUser(
            BusinessActionContext actionContext,
            @BusinessActionContextParameter(paramName = "phoneNum") String phoneNum
    );

    /**
     * commit操作-注册用户
     *
     * @param actionContext 上下文
     * @return true/false
     */
    boolean commitRegisterUser(BusinessActionContext actionContext);

    /**
     * rollback操作-注册用户
     *
     * @param actionContext 上下文
     * @return true/false
     */
    boolean cancelRegisterUser(BusinessActionContext actionContext);

}